import { Config } from "./config"

export class Socket{
    Echo(){
        return new Promise((resolve,reject)=>{
            console.log("onload");
            var sock = null;
            sock = new WebSocket(Config.wsurl);

            // 打开Socket
            sock.onopen = function() {
                console.log("connected to " + Config.wsurl);
                sock.send("xwj");
            };

            // 监听Socket的关闭
            sock.onclose = function(e) {
                console.log("test-->"+e);
            };

            //接收信息
            sock.onmessage = function(e) {
                resolve(JSON.parse(e.data));
            };
        });
    }


}
